#include<stdio.h>
#include "student.h"
void read(FILE *fp,int index);
int main(int argc,char const *argv[]){
    FILE *fp = fopen("D:/tmp/student.data","r");
    if(fp){
        fseek(fp,0L, SEEK_END);
        long size = ftell(fp);
        int number =size/sizeof(Student);
        int index = 0;
        printf("There is %d data, which do you want to see:",number);
        scanf("%d",&index);
        read(fp,index-1);
        fclose(fp);
    }
    return 0;
}

void read(FILE *fp,int index){
    fseek(fp,index*sizeof(Student), SEEK_SET);
    Student stu;
   //printf("%d\n", fread(&stu,sizeof(Student),1,fp));
    if(fread(&stu,sizeof(Student),1,fp)==1){
        printf("第%d个学生:",index+1);
        printf("\t姓名:%s\n",stu.name);
        printf("\t性别:");
        switch(stu.gender){
            case 0:printf("男\n");break;
            case 1:printf("女\n");break;
            case 2:printf("其他\n");break;
        }
        printf("\t年龄:%d\n",stu.age);
    }else{
        printf("can't open the document");
    }
}